<template>
  <view>
    <view class="logo">
      <image src="https://qn.boruichengyi.com/static/index/logo.png" mode="" style="width: 208rpx; height: 208rpx; border-radius: 20rpx 20rpx 20rpx 20rpx"></image>
    </view>
    <button class="loginbtn" open-type="getPhoneNumber" @getphonenumber="getusernumbertoken">快捷登录</button>

    <view class="footer">
      <label class="radio">
        <radio class="check" color="#0398FF" :checked="checkstate" @click="changecheckstate" />
      </label>
      <view>
        <text>
          注册登录即表示同意
          <text class="textcolor" @click="gouseragreement">《用户协议》</text>
          <text class="textcolor" @click="goparivacy">《隐私政策》</text>
          并授权 闪验获取本机号码
        </text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      checkstate: false, // 是否同意用户协议
      mobile: '', // 获取用户 手机号
      phone_code: '', // 获取手机code
      code: '' // uni.login登录时的code
    };
  },
  onLoad() {
    this.checkstate = false;
  },
  methods: {
    // 改变选中的时的状态
    changecheckstate() {
      this.checkstate = !this.checkstate;
    },

    // 获取用户手机号的code
    getusernumbertoken(e) {
      if (!this.checkstate) {
        uni.showToast({
          title: '请先勾选协议',
          icon: 'none'
        });
        return;
      }
      if (!e.detail.code) {
        uni.showToast({
          title: '获取手机号失败',
          icon: 'none'
        });
        return false;
      }
      uni.login({
        success: async (res) => {
          // 调取登录接口
          const res2 = await uni.$http.post('user/mobilelogin', {
            code: res.code, // login的code
            encrypted_data: e.detail.encryptedData, // 用户信息
            iv: e.detail.iv,
            phone_code: e.detail.code
          });
          // console.log(res2);
          if (res2.data.code == 1) {
            uni.setStorageSync('userinfo', JSON.stringify(res2.data.data.userinfo));
            uni.showToast({
              title: '登录成功',
              icon: 'none'
            });
            uni.switchTab({
              url: '/pages/index/index'
            });
          }
        }
      });
    },

    // 点击跳转到用户协议
    gouseragreement() {
      uni.navigateTo({
        url: '/sub_my/useragreement/useragreement'
      });
    },
    // 跳转到隐私协议
    goparivacy() {
      uni.navigateTo({
        url: '/sub_my/privacy/privacy'
      });
    }
  }
};
</script>

<style>
.logo {
  width: 208rpx;
  height: 208rpx;
  text-align: center;
  line-height: 208rpx;

  margin: 262rpx 270rpx 0 272rpx;
}
.loginbtn {
  width: 690rpx;
  height: 90rpx;
  margin-top: 96rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
  border-radius: 46rpx 46rpx 46rpx 46rpx;
  color: #fff;
  font-size: 30rpx;
  text-align: center;
  line-height: 90rpx;
  background: linear-gradient(#0091ff, #21e5ff);
}
.footer {
  position: fixed;
  display: flex;
  width: 600rpx;
  height: 64rpx;
  font-size: 24rpx;
  bottom: 46rpx;
  margin: 0 42rpx;
}
.textcolor {
  color: #0398ff;
}
.radio {
  font-size: 24rpx;
}

.check {
  transform: scale(0.7);
}
</style>